﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SharpSoft.WPF.Masks
{
    using System.Windows;
    using System.Windows.Media;
    /// <summary>
    /// 用于显示遮罩层
    /// </summary>
    public class MaskLayout : System.Windows.Controls.ContentControl
    {
        static MaskLayout()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MaskLayout), new FrameworkPropertyMetadata(typeof(MaskLayout)));
        }

        public MaskLayout()
        {
            this.Focusable = true;
            this.HorizontalContentAlignment = HorizontalAlignment.Center;
            this.VerticalContentAlignment = VerticalAlignment.Center;
            this.Loaded += MaskLayout_Loaded;
        }

        private void MaskLayout_Loaded(object sender, RoutedEventArgs e)
        {
            if (SetFocusOnMask)
            {
                this.Focus();////使弹出层获得焦点，避免焦点停留在底层，用户的键盘操作会依然有效。20210104
            }

        }

        public bool SetFocusOnMask { get; set; } = false;

        /// <summary>
        /// 遮罩层画刷
        /// </summary>
        public Brush MaskBrush
        {
            get { return (Brush)GetValue(MaskBrushProperty); }
            set { SetValue(MaskBrushProperty, value); }
        }

        public static readonly DependencyProperty MaskBrushProperty =
            DependencyProperty.Register("MaskBrush", typeof(Brush), typeof(MaskLayout), new PropertyMetadata(Brushes.Black));


        /// <summary>
        /// 遮罩层透明度
        /// </summary>
        public double MaskOpacity
        {
            get { return (double)GetValue(MaskOpacityProperty); }
            set { SetValue(MaskOpacityProperty, value); }
        }

        public static readonly DependencyProperty MaskOpacityProperty =
            DependencyProperty.Register("MaskOpacity", typeof(double), typeof(MaskLayout), new PropertyMetadata(0.5d));

        /// <summary>
        /// 遮罩层包含的内容
        /// </summary>
        public object MaskContent
        {
            get { return (object)GetValue(MaskContentProperty); }
            set { SetValue(MaskContentProperty, value); }
        }

        public static readonly DependencyProperty MaskContentProperty =
            DependencyProperty.Register("MaskContent", typeof(object), typeof(MaskLayout), new PropertyMetadata(null));

    }

}
